// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include "UIManager.h"
#include "Spaceship.h"
#include "Planet.h"

using namespace std;

UIManager* UIManager::_pInstance = 0;

UIManager::UIManager(void)
{
}

UIManager::~UIManager(void)
{
	if(_pInstance!=0) {
		delete _pInstance;
	}
}

UIManager* UIManager::getInstance()
{
	if(_pInstance==0) {
		_pInstance = new UIManager;
	}

	return _pInstance;
}

// Initialises the panels
void UIManager::initialize()
{
	_topPanel.createPanel();
	_planetPanel.createPanel();
	_spaceshipPanel.createPanel();
	_topPanel.display();
}

// Displays the info window for a specific unit
void UIManager::displayRightPanel(SpaceObject * unit)
{
	if(unit!=NULL){
		if (typeid(*unit) == typeid(Spaceship)) {
			_spaceshipPanel.setObserved(unit);
			_planetPanel.hide();
			_spaceshipPanel.display();

		} else if (typeid(*unit) == typeid(Planet)) {
			_planetPanel.setObserved(unit);
			_spaceshipPanel.hide();
			_planetPanel.display();
		}
	}
}

// Undisplays the right panel
void UIManager::hideRightPanel()
{
	_spaceshipPanel.hide();
	_planetPanel.hide();
}


// param timestep: time since the last update, in seconds
// param totalTime: total time the game has been running
void UIManager::update(float timestep, float totalTime)
{
	_topPanel.update(timestep, totalTime);
	if(_planetPanel.isVisible()) _planetPanel.update(timestep, totalTime);
	if(_spaceshipPanel.isVisible()) _spaceshipPanel.update(timestep, totalTime);
}

void UIManager::addDecorationPanel(ImagePanel* ip){
	
	_decorationPanels.push_back(ip);

	return;
}